package com.zhj.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 力扣 94 二叉树的中序遍历
 */
public class Test94 {

    public static void main(String[] args) {
        TreeNode root = new TreeNode(0);
        root.left = new TreeNode(1);
        root.right = new TreeNode(1);
        root.left.left = new TreeNode(2);
        root.right.right = new TreeNode(3);
        List<Integer> list = inorderTraversal(root);
        list.forEach(i -> System.out.println(i));
    }
    
    public static List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        inorder(root, res);
        return res;
    }

    private static void inorder(TreeNode root, List<Integer> res) {
        if (root == null) return;
        inorder(root.left, res);
        res.add(root.val);
        inorder(root.right, res);
    }
}
